package com.my.number;

import cn.hutool.core.util.HexUtil;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * @author: marshal
 * @date: 2022-08-01 16:11
 */
public class NumberBaseConvert {
    public static void main(String[] args) {
//        // 16进制数字符
        String hexStr = "4120313820303031203230323230373236203232343132382037203020312032203420352039203320322030203030303030303036383220302030203020302030203020312030303030303030383337203130203030303136302030203030303030303032303120312032200a";
        System.out.println(hexStr.length());
        byte[] bytes = hexToByteArray(hexStr);
        System.out.println(bytes.length);
        System.out.println(Arrays.toString(bytes));
        System.out.println(byteArrayToString(bytes));
        String s = HexUtil.decodeHexStr(hexStr);
        System.out.println(Arrays.toString(s.split("\n")));
//        String hexStr2 = "ff1b0900000000000000007676ff100900000100000000000102ff110900000200000000000305ff200900000000000000006a6aff360900000000000000000000ff160701140c0509021243ff120b0000700000000000000030a0ff380900000000000000000000";
//        System.out.println(Arrays.toString(hexToByteArray(hexStr2)));
//        System.out.println(byteArrayToString(hexToByteArray(hexStr2)));
//        System.out.println(HexUtil.decodeHexStr(hexStr2));
        String hexStr3 = "aaaa12000230303731313534333136303630303038011ee2eeeeaaaa12000230303731313534333136303630303038011ee2eeeeaaaaaa000130303731313534333136303630303038473130324c323033313130373131310001e607071a05f700040b00b004000000000000000000000000000000000000000000000000000000000c00b004000000000000000000000000000000000000000000000000000000001f00b004000000000000000000000000000000000000000000000000000000002000b004000000000000000000000000000000000000000000000000000000002d37eeeeaaaa12000230303731313534333136303630303038011ee2eeeefefefefefe820004630171010000aaaa12000230303731313534333136303630303038011ee2eeee";
        System.out.println(Arrays.toString(hexToByteArray(hexStr3)));
        System.out.println(byteArrayToString(hexToByteArray(hexStr3)));
        System.out.println(Integer.parseInt("07D0", 16));

    }


    /**
     *  16进制字符串转byte数组
     *
     * @param hexStr 16进制字符
     * @return byte数组
     */
    private static byte[] hexToByteArray(String hexStr) {
        return HexUtil.decodeHex(hexStr);
    }

    /**
     *  byte数组转String
     *
     * @param bytes byte数组
     * @return 字符串
     */
    private static String byteArrayToString(byte[] bytes) {
        return new String(bytes, StandardCharsets.UTF_8);
    }
}
